package com.corona.game;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import com.corona.Game;
import com.corona.game.util.TextureCache;
import java.util.HashMap;
import java.util.Iterator;

/* compiled from: Menu.java */
/* loaded from: pokewilds.jar:com/pkmngen/game/DrawMiniMap.class */
public class DrawMiniMap extends Menu {
    Sprite arrow;
    Sprite arrowWhite;
    Vector2 currOffset;
    Texture texture;
    int moveTimer;
    boolean justTouched;
    Vector3 touchPos;
    Vector3 prevTouchPos;
    int arrowTimer;
    Vector2 playerPos;
    Vector2 spawnLoc;
    float currX;
    float currY;
    public Action.Layer layer;
    int cursorDelay;
    Sprite spritePart;
    Sprite zSprite;
    Sprite bagSprite;
    Texture backTexture;
    Pixmap warpTilePixmap;
    Texture warpTileTexture;
    Texture warpTileTexture2;
    public static HashMap<Vector2, Tile> warpTiles = new HashMap<>();
    Tile nearestWarpTile;
    Vector2 startPos;
    Vector2 endPos;
    DrawText drawText;
    boolean snapTo;
    Vector2 cursorPos;
    Pokemon teleportPokemon;

    public DrawMiniMap(Game game, Menu prevMenu) {
        this(game, null, prevMenu);
    }

    public DrawMiniMap(Game game, Pokemon teleportPokemon, Menu prevMenu) {
        this.currOffset = new Vector2();
        this.moveTimer = 0;
        this.justTouched = true;
        this.touchPos = new Vector3();
        this.prevTouchPos = new Vector3();
        this.arrowTimer = 0;
        this.playerPos = new Vector2();
        this.spawnLoc = new Vector2();
        this.currX = 0.0f;
        this.currY = 0.0f;
        this.layer = Action.Layer.map_neg_1;
        this.startPos = new Vector2();
        this.endPos = new Vector2();
        this.snapTo = false;
        this.cursorPos = new Vector2();
        this.teleportPokemon = null;
        this.teleportPokemon = teleportPokemon;
        this.prevMenu = prevMenu;
        this.disabled = false;
        this.cursorDelay = 0;
        this.arrow = new Sprite(TextureCache.get(Gdx.files.internal("battle/arrow_right1.png")), 0, 0, 5, 7);
        this.arrowWhite = new Sprite(TextureCache.get(Gdx.files.internal("battle/arrow_right_white.png")), 0, 0, 5, 7);
        this.texture = TextureCache.get(game.map.minimap);
        this.spritePart = new Sprite(game.player.currSprite);
        this.spritePart.setRegionHeight(11);
        this.zSprite = new Sprite(TextureCache.get(Gdx.files.internal("tiles/zs1.png")), 0, 0, 16, 16);
        this.bagSprite = new Sprite(TextureCache.get(Gdx.files.internal("tiles/sleeping_bag1.png")), 0, 0, 24, 16);
        this.backTexture = TextureCache.get(Gdx.files.internal("battle/intro_frame3.png"));
        this.drawText = new DrawText(null);
        this.warpTileTexture2 = TextureCache.get(Gdx.files.internal("tiles/warp_tile1_light.png"));
    }

    @Override // com.corona.game.Action
    public String getCamera() {
        return "map";
    }

    @Override // com.corona.game.Action
    public Action.Layer getLayer() {
        return this.layer;
    }

    @Override // com.corona.game.Action
    public void firstStep(Game game) {
        this.playerPos.x = (float) (((int) (game.player.position.x - game.map.bottomLeft.x)) / 8);
        this.playerPos.y = (float) (((int) (game.player.position.y - game.map.bottomLeft.y)) / 8);
        this.spawnLoc.x = (float) (((int) (game.player.spawnLoc.x - game.map.bottomLeft.x)) / 8);
        this.spawnLoc.y = (float) (((int) (game.player.spawnLoc.y - game.map.bottomLeft.y)) / 8);
        this.currX = game.cam.position.x - this.playerPos.x;
        this.currY = game.cam.position.y - this.playerPos.y;
        this.currOffset.x = 0.0f;
        this.currOffset.y = 0.0f;
        this.cursorPos.set(game.cam.position.x, game.cam.position.y);
        this.warpTilePixmap = new Pixmap(game.map.minimap.getWidth(), game.map.minimap.getHeight(), Pixmap.Format.RGBA8888);
        for (Tile tile : warpTiles.values()) {
            this.warpTilePixmap.drawPixmap(tile.overSprite.getPixmap(), (((int) (tile.position.x - game.map.bottomLeft.x)) / 8) - 8, (((int) (game.map.topRight.y - tile.position.y)) / 8) - 8, tile.overSprite.getRegionX(), tile.overSprite.getRegionY(), tile.overSprite.getRegionWidth(), tile.overSprite.getRegionHeight());
        }
        this.warpTileTexture = TextureCache.get(this.warpTilePixmap);
        game.insertAction(this.drawText);
        if (this.teleportPokemon == null) {
            Iterator<Pokemon> it = game.player.pokemon.iterator();
            while (it.hasNext()) {
                Pokemon pokemon = it.next();
                if (!pokemon.isEgg && pokemon.hms.contains("TELEPORT")) {
                    this.teleportPokemon = pokemon;
                    return;
                }
            }
        }
    }

    @Override // com.corona.game.Action
    public void step(Game game) {
        this.arrowTimer++;
        if (this.arrowTimer > 80) {
            this.arrowTimer = 0;
        }
        game.mapBatch.flush();
        Gdx.gl.glClear(16384);
        game.mapBatch.draw(this.texture, this.currX + this.currOffset.x, this.currY + this.currOffset.y);
        if (this.arrowTimer < 40) {
            game.mapBatch.draw(this.warpTileTexture, this.currX + this.currOffset.x, this.currY + this.currOffset.y);
            game.mapBatch.draw(this.bagSprite, ((this.currX + this.currOffset.x) + this.spawnLoc.x) - 12.0f, ((this.currY + this.currOffset.y) + this.spawnLoc.y) - 8.0f);
            game.mapBatch.draw(this.zSprite, this.currX + this.currOffset.x + this.spawnLoc.x + 4.0f, this.currY + this.currOffset.y + this.spawnLoc.y + 4.0f);
            game.mapBatch.draw(this.spritePart, ((this.currX + this.currOffset.x) + this.playerPos.x) - 8.0f, (((this.currY + this.currOffset.y) + this.playerPos.y) + 5.0f) - 8.0f);
        }
        if (this.nearestWarpTile != null) {
            game.mapBatch.draw(this.warpTileTexture2, ((this.currX + this.currOffset.x) + ((float) (((int) (this.nearestWarpTile.position.x - game.map.bottomLeft.x)) / 8))) - 8.0f, (((this.currY + this.currOffset.y) + ((float) (((int) (this.nearestWarpTile.position.y - game.map.bottomLeft.y)) / 8))) - 8.0f) + 2.0f);
            if (this.nearestWarpTile.hasItem != null && this.drawText.text == null) {
                this.drawText.text = this.nearestWarpTile.hasItem;
            }
        } else {
            this.drawText.text = null;
        }
        if (this.goAway) {
            this.texture.dispose();
            this.warpTileTexture.dispose();
            game.actionStack.remove(this.drawText);
            game.actionStack.remove(this);
        }
        if (!this.disabled) {
            this.snapTo = true;
            if (InputProcessor.upPressed) {
                this.moveTimer++;
                if (this.moveTimer >= 1) {
                    this.moveTimer = 0;
                    this.currY -= 2.0f;
                    this.cursorPos.y += 16.0f;
                }
                this.snapTo = false;
            } else if (InputProcessor.downPressed) {
                this.moveTimer++;
                if (this.moveTimer >= 1) {
                    this.moveTimer = 0;
                    this.currY += 2.0f;
                    this.cursorPos.y -= 16.0f;
                }
                this.snapTo = false;
            }
            if (InputProcessor.rightPressed) {
                this.moveTimer++;
                if (this.moveTimer >= 1) {
                    this.moveTimer = 0;
                    this.currX -= 2.0f;
                    this.cursorPos.x += 16.0f;
                }
                this.snapTo = false;
            } else if (InputProcessor.leftPressed) {
                this.moveTimer++;
                if (this.moveTimer >= 1) {
                    this.moveTimer = 0;
                    this.currX += 2.0f;
                    this.cursorPos.x -= 16.0f;
                }
                this.snapTo = false;
            }
            this.touchPos.x = (float) Gdx.input.getX();
            this.touchPos.y = (float) Gdx.input.getY();
            game.cam.unproject(this.touchPos);
            if (Gdx.input.isTouched()) {
                if (this.justTouched) {
                    this.prevTouchPos = this.touchPos.cpy();
                }
                this.justTouched = false;
                int amtX = (int) (this.touchPos.x - this.prevTouchPos.x);
                int amtY = (int) (this.touchPos.y - this.prevTouchPos.y);
                this.currX += (float) amtX;
                this.currY += (float) amtY;
                this.cursorPos = this.cursorPos.sub((float) (amtX * 8), (float) (amtY * 8));
                this.prevTouchPos = this.touchPos.cpy();
                this.snapTo = false;
            } else {
                this.justTouched = true;
            }
            this.nearestWarpTile = null;
            this.startPos.set(this.cursorPos.x, this.cursorPos.y);
            this.startPos.x -= (float) (Math.floorMod((int) this.startPos.x, 16) + 80);
            this.startPos.y -= (float) (Math.floorMod((int) this.startPos.y, 16) + 80);
            this.endPos.set(this.startPos.x, this.startPos.y);
            this.endPos.x += 160.0f;
            this.endPos.y += 160.0f;
            Vector2 currPos = this.startPos.cpy();
            while (true) {
                if (currPos.y > this.endPos.y) {
                    break;
                }
                Tile tile = warpTiles.get(currPos);
                currPos.x += 16.0f;
                if (currPos.x > this.endPos.x) {
                    currPos.x = this.startPos.x;
                    currPos.y += 16.0f;
                }
                if (tile != null) {
                    this.nearestWarpTile = tile;
                    break;
                }
            }
            if (this.snapTo && this.nearestWarpTile != null) {
                this.currX = game.cam.position.x - ((float) (((int) (this.nearestWarpTile.position.x - game.map.bottomLeft.x)) / 8));
                this.currY = game.cam.position.y - ((float) (((int) (this.nearestWarpTile.position.y - game.map.bottomLeft.y)) / 8));
                this.cursorPos.set(this.nearestWarpTile.position.x, this.nearestWarpTile.position.y);
            }
            if (InputProcessor.bJustPressed) {
                this.texture.dispose();
                this.warpTileTexture.dispose();
                if (this.prevMenu != null) {
                    this.prevMenu.disabled = false;
                }
                game.actionStack.remove(this.drawText);
                game.actionStack.remove(this);
                game.insertAction(new DrawPokemonMenu.Intro(this.prevMenu));
                game.insertAction(new PlayMusic("click1", (Action) null));
            } else if (InputProcessor.aJustPressed && this.teleportPokemon != null && this.nearestWarpTile != null) {
                this.disabled = true;
                DrawText drawText = new DrawText(this.nearestWarpTile.hasItem);
                Runnable r28 = ()
                /*  JADX ERROR: Method code generation error
                    jadx.core.utils.exceptions.CodegenException: Error generate insn: 0x05e6: INVOKE_CUSTOM (r28v1 'r28' java.lang.Runnable) =
                      (r86v0 'this' com.corona.game.DrawMiniMap A[D('this' com.corona.game.DrawMiniMap), DONT_INLINE, IMMUTABLE_TYPE, THIS])
                      (r87v0 'game' com.corona.Game A[D('game' com.corona.Game), DONT_INLINE])

                     handle type: INVOKE_DIRECT
                     lambda: java.lang.Runnable.run():void
                     call insn: ?: INVOKE  (r28 I:com.corona.game.DrawMiniMap), (r29 I:com.corona.Game) type: DIRECT call: com.corona.game.DrawMiniMap.lambda$step$0(com.corona.Game):void in method: com.corona.game.DrawMiniMap.step(com.corona.Game):void, file: pokewilds.jar:com/pkmngen/game/DrawMiniMap.class
                    	at jadx.core.codegen.InsnGen.makeInsn(InsnGen.java:285)
                    	at jadx.core.codegen.InsnGen.makeInsn(InsnGen.java:248)
                    	at jadx.core.codegen.RegionGen.makeSimpleBlock(RegionGen.java:105)
                    	at jadx.core.dex.nodes.IBlock.generate(IBlock.java:15)
                    	at jadx.core.codegen.RegionGen.makeRegion(RegionGen.java:65)
                    	at jadx.core.dex.regions.Region.generate(Region.java:35)
                    	at jadx.core.codegen.RegionGen.makeRegion(RegionGen.java:65)
                    	at jadx.core.codegen.RegionGen.makeRegionIndent(RegionGen.java:94)
                    	at jadx.core.codegen.RegionGen.makeIf(RegionGen.java:137)
                    	at jadx.core.codegen.RegionGen.connectElseIf(RegionGen.java:170)
                    	at jadx.core.codegen.RegionGen.makeIf(RegionGen.java:147)
                    	at jadx.core.dex.regions.conditions.IfRegion.generate(IfRegion.java:137)
                    	at jadx.core.codegen.RegionGen.makeRegion(RegionGen.java:65)
                    	at jadx.core.dex.regions.Region.generate(Region.java:35)
                    	at jadx.core.codegen.RegionGen.makeRegion(RegionGen.java:65)
                    	at jadx.core.codegen.RegionGen.makeRegionIndent(RegionGen.java:94)
                    	at jadx.core.codegen.RegionGen.makeIf(RegionGen.java:137)
                    	at jadx.core.dex.regions.conditions.IfRegion.generate(IfRegion.java:137)
                    	at jadx.core.codegen.RegionGen.makeRegion(RegionGen.java:65)
                    	at jadx.core.dex.regions.Region.generate(Region.java:35)
                    	at jadx.core.codegen.RegionGen.makeRegion(RegionGen.java:65)
                    	at jadx.core.codegen.MethodGen.addRegionInsns(MethodGen.java:261)
                    	at jadx.core.codegen.MethodGen.addInstructions(MethodGen.java:254)
                    	at jadx.core.codegen.ClassGen.addMethodCode(ClassGen.java:349)
                    	at jadx.core.codegen.ClassGen.addMethod(ClassGen.java:302)
                    	at jadx.core.codegen.ClassGen.lambda$addInnerClsAndMethods$2(ClassGen.java:271)
                    	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
                    	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
                    	at java.base/java.util.stream.SortedOps$RefSortingSink.end(SortedOps.java:395)
                    	at java.base/java.util.stream.Sink$ChainedReference.end(Sink.java:261)
                    Caused by: java.lang.IndexOutOfBoundsException: Index 1 out of bounds for length 1
                    	at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:100)
                    	at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:106)
                    	at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:302)
                    	at java.base/java.util.Objects.checkIndex(Objects.java:385)
                    	at java.base/java.util.ArrayList.get(ArrayList.java:427)
                    	at jadx.core.codegen.InsnGen.makeInlinedLambdaMethod(InsnGen.java:909)
                    	at jadx.core.codegen.InsnGen.makeInvokeLambda(InsnGen.java:814)
                    	at jadx.core.codegen.InsnGen.makeInvoke(InsnGen.java:756)
                    	at jadx.core.codegen.InsnGen.makeInsnBody(InsnGen.java:397)
                    	at jadx.core.codegen.InsnGen.makeInsn(InsnGen.java:278)
                    	... 29 more
                    */
                /*
                // Method dump skipped, instructions count: 1768
                */
                throw new UnsupportedOperationException("Method not decompiled: com.corona.game.DrawMiniMap.step(com.corona.Game):void");
            }

            /* compiled from: Menu.java */
            /* loaded from: pokewilds.jar:com/pkmngen/game/DrawMiniMap$Intro.class */
            static class Intro extends Action {
                int length;
                public Action.Layer layer = Action.Layer.gui_110;
                Menu prevMenu;

                public Intro(Menu prevMenu, int length, Action nextAction) {
                    super(new Object[0]);
                    this.prevMenu = prevMenu;
                    this.nextAction = nextAction;
                    this.length = length;
                }

                @Override // com.corona.game.Action
                public String getCamera() {
                    return "gui";
                }

                @Override // com.corona.game.Action
                public Action.Layer getLayer() {
                    return this.layer;
                }

                @Override // com.corona.game.Action
                public void step(Game game) {
                    if (this.prevMenu != null) {
                        this.prevMenu.step(game);
                    }
                    this.length--;
                    if (this.length <= 0) {
                        game.insertAction(this.nextAction);
                        game.actionStack.remove(this);
                    }
                }
            }
        }
